import time
import requests
import yaml
import os
import sys

curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)

class BaseApi:
    from common.tools import Tools
    from common.logger import get_logger
    # root_path = Tools().get_rootdir()
    tool = Tools()
    logger = get_logger('baseapi')

    def send(self, request_data: dict):
        self.logger.info('请求数据:{}'.format(request_data))
        try:
            env = self.tool.get_env()
            request_data['url'] = env + request_data['url']
            response = requests.request(**request_data)
            self.logger.info('响应码:{}'.format(response.status_code))
            self.logger.info('响应text:{}'.format(response.text))
            return response
        except Exception as e:
            self.logger.error(e)
            # raise e


if __name__ == '__main__':
    print(BaseApi().send({'method': 'post', "url": "/admin-api/system/auth/sms-login-password",
                          'json': {'mobile': 18700000003, 'password': 123456}}).json())
    # BaseApi().set_global(data={'phon1e': 123})
    # print(BaseApi().get_global('phone'))
    # BaseApi().set_new_token_to_global(1040903639)
    pass
